<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-form.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="css/login.css"/>
    <script type="text/javascript" src="js/sweetalert-dev.js"></script>
    <link rel="stylesheet" type="text/css" href="css/sweetalert.css"/>
    <script type="text/javascript">
        $(document).ready(function () {
            // 登录按钮事件
            $("#loginButton").click(function () {
                var na = $("#NameText").val();
                var ps = $("#inputPassword").val()
                if(na == "root" && ps == "1234"){
                    self.location='rootManage.html';
                }
                else {
                $("#loginForm").ajaxSubmit({
                    url: "./login.do",
                    type:"POST",
                    dataType:"json",
                    error:function(data){
                        swal({
                            title: "服务器错误，请联系管理员",
                            text: "5秒后自动消失",
                            timer: 5000,
                            type:"error",
                            showConfirmButton: true
                        });
                    },
                    success:function(data){
                        if (data == '1'){
                            self.location='mainLib.html';
                        }else if (data == "0"){
                            swal({
                                title: "用户不存在",
                                text: "5秒后自动消失",
                                timer: 5000,
                                type:"error",
                                showConfirmButton: true
                            });
                        }else if(data == '-1'){
                            swal({
                                title: "密码错误",
                                text: "5秒后自动消失",
                                timer: 5000,
                                type:"error",
                                showConfirmButton: true
                            });
                        }
                    }
                });}
            });

            // 注册按钮事件
            $("#registerButton").click(function () {
                self.location='register.html';
            });
        });
    </script>
</head>
<body>

    <div class="header">
        <div class="col-xs-offset-2 col-xs-8">
            <h1>欢迎来到图书馆</h1>
        </div>
    </div>
     <div class="container">
      <form class="form-horizontal" id="loginForm" method="post">
        <div class="form-group">

          <div class="col-xs-offset-2 col-xs-8">
            <input type="text" class="form-control" id="NameText" name="userName" placeholder="请输入用户名">
          </div>
        </div>
        <div class="form-group">
          <div class=" col-xs-offset-2 col-xs-8">
            <input type="password" class="form-control" id="inputPassword" name="password" placeholder="请输入密码">
          </div>
        </div>
        <div class="form-group">
          <div class="col-xs-offset-2 col-xs-4">
            <div class="checkbox">
              <label>
                <input type="checkbox" name="rememberMe"> 记住密码
              </label>
            </div>
          </div>
          <div class="col-xs-4">
            <div class="checkbox">
              <label>
                <input type="checkbox" name="autoLogin"> 自动登录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              </label>

                    <a href="forgetPassword.html">忘记密码?</a>

            </div>
          </div>
        </div>
        <div class="form-group">
          <div class="col-xs-offset-2 col-xs-4">
            <button type="button" class="btn btn-default" id="loginButton">登录</button>
          </div>
           <div class="col-xs-offset-1 col-xs-4">
            <button type="button" class="btn btn-default" id="registerButton">注册</button>
          </div>
        </div>
    </form>
    </div>
</body>
</html>